﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

/// <summary>
/// Summary description for RoleBusiness
/// </summary>
public class RoleBusiness
{
	public RoleBusiness()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public bool Insert(RoleEntities item)
    {
        bool flat = false;
        string[] para = { "@roleName" };
        string[] values = { item._roleName };
        if (DataAccess.getExecProcedure("sp_InsertRole", para, values) > 0)
        {
            flat = true;
        }
        else
            flat = false;
        return flat;
    }

    public bool Edit(RoleEntities item)
    {
        bool flat = false;
        string[] para = { "@roleID","@roleName" };
        string[] values = { item._roleID.ToString(),item._roleName };
        if (DataAccess.getExecProcedure("sp_UpdateRole", para, values) > 0)
            flat = true;
        else
            flat = false;
        return flat;
    }

    public bool Delete(int id)
    {
        if (DataAccess.getExec("exec sp_DeleteRole '" + id + "'") > 0)
            return true;
        else
            return false;
    }

    public DataTable getAllRole()
    {
        return DataAccess.DataTable_Query("exec sp_GetRole '0'");
    }
    public RoleEntities getRole(int id)
    {
        DataTable dt=DataAccess.DataTable_Query("exec sp_GetRole '"+id+"'");
        RoleEntities re=new RoleEntities();
        if(dt!=null)
        {
            DataRow dr=dt.Rows[0];
            re._roleID=int.Parse(dr["roleID"].ToString());
            re._roleName=dr["roleName"].ToString();
        }
        return re;
    }
    public DataTable getRoleBy(string[] TableName, string[] fields, string Criterias, string priorities)
    {
        DataTable dt = new DataTable();
        string query = SQLQuery.SQLQuery_SELECT(TableName, fields, Criterias, priorities);
        return dt = DataAccess.DataTable_Query(query);
    }
}